#include "head.h"

int init_pool(Process poll[], int n)
{
    for(int i = 0; i < n; ++i)
    {
        int sv[2] = {0};
        if(socketpair(AF_LOCAL, SOCK_STREAM, 0, sv) == -1)
            error(1, errno, "socketpair");

        pid_t pid = fork();
        if(pid == 0)
        {

            close(sv[1]);
            // 子进程
            printf("son\n");
            son(sv[0]);
            
        }
        else
        {
            close(sv[0]);
            // 父进程
            poll[i].pid = pid;
            poll[i].local_fd = sv[1];
            poll[i].state = FREE;
        }
    }

    return 0;
}
